package com.genius.unite_platform.device.controller;

import com.alibaba.fastjson.JSONObject;
import com.genius.adminmanager.other.entity.ResponseJson;
import com.genius.unite_platform.device.service.DeviceService;
import com.genius.workflow.log.ControllerLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class DeviceInsertController {

	@Autowired
    @Qualifier("DeviceInsertService")
    private DeviceService DeviceInsertService;

	/**
	 * 跳转到新的新增页面
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@RequiresPermissions("194761610645435eb03e49cc893cdb41")
	@PostMapping("/device/toInsert")
	public String toInsert(){
		return "/views/unite_platform/device/insert";
	}


	/**
	 * 添加操作
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@ControllerLog(description="添加设备类型")
	@PostMapping("/Device/add")
	@ResponseBody
	public JSONObject add(@RequestBody JSONObject json,HttpSession session){
		JSONObject response = new JSONObject();
    	response.put(ResponseJson.code, 0);
    	response = DeviceInsertService.add(json, response,session);
		return response;
	}

	/**
	 * 新增填充操作
	 * @param session
	 * @return
	 * @throws Exception
	 */
	@PostMapping("/device/fillAdd")
	@ResponseBody
	public JSONObject fillAdd(@RequestBody JSONObject json){
		JSONObject response = new JSONObject();
    	response.put(ResponseJson.code, 0);
    	response = DeviceInsertService.fillAdd(json, response);
		return response;
	}

}




